import java.io.*;
import java.util.*;

/**
 * #Problema 10010 - Where is Waldorf?
 * Uva Online judge contest
 * Solved by Jonas Jeske
 * @author jonas
 * http://www.inf.ufrgs.br/~jjeske
 *
 */
public class Main {
	
	private char[][] matrix;
	private int nnSize;
	private int mmSize;
	public Scanner entrada = new Scanner(System.in);
	public PrintStream saida = new PrintStream(System.out);
		
	public static void main(String[] args){
		Main whereIsWaldorf = new Main();
		whereIsWaldorf.begin();
	}
	
	void begin(){
		int cases;
		int mSize, nSize;
		int nWords;
		String[] wordList;
		String auxString;
		String entradao;
		mSize = 0;
		nSize = 0;
		nnSize = 0;
		mmSize =0;
		auxString = null;		
		
		cases = entrada.nextInt();		
		for(int testCase=0; testCase < cases; testCase++){
			mSize = 0;
			nSize = 0;
			nnSize = 0;
			mmSize =0;
			
			entrada.useDelimiter(System.getProperty("line.separator"));
			entradao = entrada.next(); //blank line for each case
			entradao = entrada.next();
			String s[] = entradao.split(" ");

			mSize = Integer.valueOf(s[0]);
			nSize = Integer.valueOf(s[1]);
			
			matrix = new char[mSize][nSize];
			nnSize = nSize;
			mmSize = mSize;
			
			//le e grava a entrada em uma matriz de chars
			for(int m=0; m < mSize; m++){
				auxString = entrada.next();
				auxString = auxString.toLowerCase();
				matrix[m] = auxString.toCharArray(); //TODO: check this
			}			
			
			nWords = entrada.nextInt();
			wordList = new String[nWords];
			for(int word=0; word < nWords; word++){ //TODO: Check if this can be done within the next for statment
				auxString = entrada.next();
				auxString = auxString.toLowerCase();
				wordList[word] = auxString;
			}
			entrada.reset();
			
			//do functions
			for (int word = 0; word < nWords; word++) {
				searchWord(wordList[word]);
			}			
			matrix = null;
			if (testCase != cases -1) {
				saida.printf("\n"); //TODO; extra \n on ending
			}
		}
	}

	private void searchWord(String stringWord) {
		for(int m=0; m<mmSize; m++){
			for(int n=0; n<nnSize; n++){
				if((matrix[m][n] == stringWord.charAt(0)) && (stringWord.length() != 1) ){ //TODO: if it is ONE LETTER WORD??
						if (searchDown(stringWord, m, n)) {
							saida.printf("%d %d\n", m + 1, n + 1);
							return;
						}
						if (searchUp(stringWord, m, n)) {
							saida.printf("%d %d\n", m + 1, n + 1);
							return;
						}
						if (searchRight(stringWord, m, n)) {
							saida.printf("%d %d\n", m + 1, n + 1);
							return;
						}
						if (searchLeft(stringWord, m, n)) {
							saida.printf("%d %d\n", m + 1, n + 1);
							return;
						}
						if (searchDownRight(stringWord, m, n)) {
							saida.printf("%d %d\n", m + 1, n + 1);
							return;
						}
						if (searchDownLeft(stringWord, m, n)) {
							saida.printf("%d %d\n", m + 1, n + 1);
							return;
						}
						if (searchUpLeft(stringWord, m, n)) {
							saida.printf("%d %d\n", m + 1, n + 1);
							return;
						}
						//Clock Spin;					
				}
				if((matrix[m][n] == stringWord.charAt(0)) && (stringWord.length() == 1)){
					saida.printf("%d %d\n", m + 1, n + 1);
					return;
				}
			}
		}
		
		//return false;
	}
	
	
	private boolean searchDown(String stringWord, int m, int n){
		boolean resultado;
		resultado = false;
		
		//constraints
		if(m + stringWord.length() > mmSize) {
			return false;
		}

		for(int position=0; position < stringWord.length(); position++){
				if(isLetterOnPosition(stringWord.charAt(position),m+position,n)) {
					resultado = true;
				} else {
					resultado = false;
					return resultado;
				}	
		}
		return resultado;
	}
	
	private boolean searchUp(String stringWord, int m, int n){
		boolean resultado;
		resultado = false;
		
		//constraints
		if(m - (stringWord.length()-1) < 0) {
			return false;
		}

		for(int position=0; position < stringWord.length(); position++){
				if(isLetterOnPosition(stringWord.charAt(position),m-position,n)) {
					resultado = true;
				} else {
					resultado = false;
					return resultado;
				}	
		}
		return resultado;
	}
	
	private boolean searchRight(String stringWord, int m, int n){
		boolean resultado;
		resultado = false;
		
		//constraints
		if(n + stringWord.length() > nnSize) {
			return false;
		}

		for(int position=0; position < stringWord.length(); position++){
				if(isLetterOnPosition(stringWord.charAt(position),m,n+position)) {
					resultado = true;
				} else {
					resultado = false;
					return resultado;
				}	
		}
		return resultado;
	}

	private boolean searchLeft(String stringWord, int m, int n){
		boolean resultado;
		resultado = false;
		
		//constraints
		if(n - (stringWord.length()-1) < 0) {
			return false;
		}

		for(int position=0; position < stringWord.length(); position++){
				if(isLetterOnPosition(stringWord.charAt(position),m,n-position)) {
					resultado = true;
				} else {
					resultado = false;
					return resultado;
				}	
		}
		return resultado;
	}
	
	private boolean searchDownRight(String stringWord, int m, int n){
		boolean resultado;
		resultado = false;
		
		//constraints
		if((m + stringWord.length() > mmSize) || (n + stringWord.length() > nnSize)) {
			return false;
		}

		for(int position=0; position < stringWord.length(); position++){
				if(isLetterOnPosition(stringWord.charAt(position),m+position,n+position)) {
					resultado = true;
				} else {
					resultado = false;
					return resultado;
				}	
		}
		return resultado;
	}
	
	private boolean searchDownLeft(String stringWord, int m, int n){
		boolean resultado;
		resultado = false;
		
		//constraints
		if((m + stringWord.length() > mmSize) || (n - (stringWord.length()-1) < 0)) { //TODO: check this constraints and the or operator
			resultado = false;
			return resultado;
		}

		for(int position=0; position < stringWord.length(); position++){
				if(isLetterOnPosition(stringWord.charAt(position),m+position,n-position)) {
					resultado = true;
				} else {
					resultado = false;
					return resultado;
				}	
		}
		return resultado;
	}
	
	private boolean searchUpLeft(String stringWord, int m, int n){
		boolean resultado;
		resultado = false;
		
		//constraints
		if((m - (stringWord.length()-1) < 0) || (n - (stringWord.length()-1) < 0)) { //TODO: check this constraints and the or operator
			resultado = false;
			return resultado;
		}

		for(int position=0; position < stringWord.length(); position++){
				if(isLetterOnPosition(stringWord.charAt(position),m-position,n-position)) {
					resultado = true;
				} else {
					resultado = false;
					return resultado;
				}	
		}
		return resultado;
	}
	
	private boolean searchUpRight(String stringWord, int m, int n){
		boolean resultado;
		resultado = false;
		
		//constraints
		if((m - (stringWord.length()-1) < 0) || (n + stringWord.length() > nnSize)) { //TODO: check this constraints and the or operator
			resultado = false;
			return resultado;
		}

		for(int position=0; position < stringWord.length(); position++){
				if(isLetterOnPosition(stringWord.charAt(position),m-position,n+position)) {
					resultado = true;
				} else {
					resultado = false;
					return resultado;
				}	
		}
		return resultado;
	}

	
	
	/**
	 * return true if char letter is on the matrix position m n
	 * @param letter
	 * @param m
	 * @param n
	 * @return
	 */
	private boolean isLetterOnPosition(char letter,int m, int n){
		if(matrix[m][n] == letter){
			return true;
		} else {
			return false;
		}
		
	}
}


